package learnProxy;

import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @author jiangfeng 2018/10/25 16:26
 */
public class TestMain {
    public static void main(String[] args) {
        XiaoXingXing xiaoXingXing = new XiaoXingXing();
        xiaoXingXing.findlove();
        System.out.println(xiaoXingXing.getClass());

        System.out.println();
        System.out.println();
        MeiPoProxy meiPoProxy = new MeiPoProxy();
        Object instance = meiPoProxy.getInstance(xiaoXingXing);
        ((Person)instance).findlove();
        System.out.println(instance.getClass());

        //meiPoProxy.invoke()
        // 动态代理:获取的被代理对象的引用和接口   重新动态生成了一个class字节码  然后编译了一个代理类

        //代理类字节码生成器

        byte[] $Rroxy0s = ProxyGenerator.generateProxyClass("$Rroxy0", new Class[]{Person.class});
        try {
            FileOutputStream fileOutputStream = new FileOutputStream("$Rroxy0.class");
            fileOutputStream.write($Rroxy0s);
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
